import 'package:flutter/material.dart';
import 'package:flutter_slidable/flutter_slidable.dart';
import 'package:get/get.dart';

import '../../common/strings.dart';
import '../../common/styles.dart';
import '../../manager/global.dart';
import '../../widgets/noteCard.dart';
import 'logic.dart';

class NoteFavoritePage extends StatelessWidget {
  NoteFavoritePage({Key? key}) : super(key: key);

  final logic = Get.put(NoteFavoriteLogic());
  final state = Get.find<NoteFavoriteLogic>().state;

  @override
  Widget build(BuildContext context) {
    return Obx(() {
      if (GlobalUtil.noteList.isEmpty || GlobalUtil.favoriteNum.value <= 0) {
        return Center(
            child: Text(
          Strings.noFavoriteNote,
          style: Styles.textTransparentMedium(30),
        ));
      }
      return Scrollbar(
        controller: state.scrollController,
        radius: const Radius.circular(15),
        thickness: 10,
        interactive: true,
        child: SlidableAutoCloseBehavior(
          child: ListView(
            padding: EdgeInsets.zero,
            controller: state.scrollController,
            children: [
              ...List.generate(GlobalUtil.noteList.length, (index) {
                if (GlobalUtil.noteList[index].isFavorite) {
                  return NoteCard(GlobalUtil.noteList[index]);
                }
                return const SizedBox();
              }),
            ],
          ),
        ),
      );
    });
  }
}
